package com.feicheng.house.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.feicheng.house.entity.Vip;
import com.feicheng.house.exception.SystemException;
import com.feicheng.house.result.ResultInfo;
import com.feicheng.house.service.IVipService;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author feichengTech
 * @since 2021-11-06
 */
@RestController
@RequestMapping("/house/vip")
public class VipController {
	
	@Autowired
	IVipService iVipService;
	
	/**
	 * 新增Vip
	 * @param vip
	 * @return 是否新增成功
	 */
	@PostMapping("/info")
	public ResultInfo addVip(@RequestBody Vip vip) {
		//检查会员信息完整性
		if (vip.getClientId() == null
				|| vip.getCardId() == null) {
			throw new SystemException("保证会员信息完整");
		}
		return iVipService.addVip(vip);
	}
	
	/**
	 * 删除会员
	 * @param vipId
	 * @return 是否删除成功
	 */
	@DeleteMapping("/info")
	public ResultInfo deleteVip(Integer vipId) {
		return iVipService.deleteVip(vipId);
	}
	
	/**
	 * 更新Vip
	 * @param vip
	 * @return 是否更新成功
	 */
	@PutMapping("/info")
	public ResultInfo updateVip(Vip vip) {
		//检查会员信息完整性
		if (//只允许改截止日期
			vip.getVipDeadline() == null
			|| vip.getVipId() == null) {
			throw new SystemException("保证会员信息完整");
		}
		return iVipService.updateVip(vip);
	}
	
//	/**
//	 * 根据Id查询会员
//	 * @param vipId
//	 * @return 查询结果
//	 */
//	@GetMapping("/info")
//	public ResultInfo getOneCard(Integer vipId) {
//		return iVipService.getOneVip(vipId);
//	}
	
}

